using System.Collections;
using System.Data;
using System.Windows.Forms;
using ctsu.Admin.Forms;
using ctsu.BaseForms;
using ctsu.Security;
using System;

namespace ctsu.Admin.BusLogic
{
	public class BLFormInvestigatorImpl : BLFormBaseImpl
	{
        protected TextBox _facultyRankOther;
        protected ComboBox _facultyRank;

		public BLFormInvestigatorImpl(FormMain formMain, FormBase form, FormInfoBase formInfo, DataTable tableSchema, Permission formSecurity, Hashtable configData)
			: base(formMain, form, formInfo, tableSchema, formSecurity, configData)
		{

		}
        
        protected override void _vcManager_OnAfterHookEvents()
        {
            base._vcManager_OnAfterHookEvents();
            _facultyRankOther = (TextBox)Forms.Utils.GetControlByName("FacultyRankOther", this._form.Controls);
            _facultyRank = (ComboBox)Forms.Utils.GetControlByName("FacultyRank", this._form.Controls);

            this._facultyRank.SelectedIndexChanged += new EventHandler(facultyRank_SelectedIndexChanged);
        }

        protected override void SetControlsEnabled(bool enable)
        {
            base.SetControlsEnabled(enable);
            if (_facultyRank.Text != "Other")
                _facultyRankOther.Enabled = false;
        }

        private void facultyRank_SelectedIndexChanged(object sender, EventArgs e)
        {
            //StringBuilder sb = new StringBuilder();
            ComboBox cbo = (ComboBox)sender;
            string sVal = cbo.Text;
            if (sVal == "Other")
            {
                _facultyRankOther.Enabled = true;
            }
            else
            { 
                _facultyRankOther.Enabled = false; 
                _facultyRankOther.Text = ""; 
            }
        }

        protected virtual bool VerifyDepartment(Control ctl)
		{
			FieldContext fc = (FieldContext)ctl.Tag;
			ComboBox cb = (ComboBox)ctl;

			if (cb.SelectedIndex == -1)
			{
				fc.ErrorMessage = "Department is a required field";
				return false;
			}

			if ((int)cb.SelectedValue < 2)
			{
				fc.ErrorMessage = "Department is a required field";
				return false;
			}

			return true;
		}

		protected virtual bool VerifyNonHost(Control ctl)
		{
			FieldContext fc = (FieldContext)ctl.Tag;
			ComboBox cb = (ComboBox)ctl;

			if (cb.SelectedIndex == -1)
			{
				fc.ErrorMessage = "Non Host is a required field";
				return false;
			}


			if ((int)cb.SelectedValue < 2)
			{
				fc.ErrorMessage = "Non Host is a required field";
				return false;
			}

			return true;
		}
	}
}
